package com.sky.yipinyoufujava.controller;


import com.sky.yipinyoufujava.pojo.HomeCarousel;
import com.sky.yipinyoufujava.pojo.from.GoodsForm;
import com.sky.yipinyoufujava.pojo.goods.Goods;
import com.sky.yipinyoufujava.pojo.goodsType.FirstGoodsType;
import com.sky.yipinyoufujava.pojo.order.OrderStatus;
import com.sky.yipinyoufujava.result.Result;
import com.sky.yipinyoufujava.service.GoodsService;
import com.sky.yipinyoufujava.service.HomeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 处理首页的数据
 */

@RestController
@Slf4j
public class HomeConteroller {
    @Autowired
    private HomeService homeService;
    @Autowired
    private GoodsService goodsService;
    @PostMapping("/getOrderStatus")
    public Result getOrderStatus(){
        List<OrderStatus> orderStatusesList =  homeService.getOrderStatus();
        return Result.success(orderStatusesList);
    }


    @PostMapping("/getHome")
    public Result getHome(){
        // 获取爆款的商品
        List<Goods> explosion = goodsService.getExplosion();
        // 获取商品列表
        List<Goods> goodsList = goodsService.getGoodsList();
        // 获取海报
        HomeCarousel poster = homeService.getPoster();
        // 获取轮播图
        List<HomeCarousel> carousel = homeService.getCarousel();
        // 获取商品分类
        List<FirstGoodsType> firstGoodsTypes = goodsService.getFirstGoodsTypes();
//        创建一个容器，装几个数据
        // 创建一个新的Map来包含User对象和token
        Map<String, Object> resultMap = new HashMap<>();
        resultMap.put("explosion", explosion);
        resultMap.put("goodsList", goodsList);
        resultMap.put("poster", poster);
        resultMap.put("carousel", carousel);
        resultMap.put("firstGoodsTypes", firstGoodsTypes);

        return Result.success(resultMap);
    }
}
